package com.zzyl.redis;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Set;

@SpringBootTest
public class testCommon {

    @Autowired
    private RedisTemplate<String,String> redisTemplate; // redisTemplate是springboot自动注入的


    /**
     * 通用命令操作
     */
    @Test
    public void testCommon(){
        //获取所有key
        Set<String> keys = redisTemplate.keys("*");
        System.out.println(keys);
        System.out.println("===================================");
        //判断key是否存在
        Boolean isName = redisTemplate.hasKey("name");
        System.out.println(isName);
        System.out.println("===================================");
        //获取key的类型
        DataType type = redisTemplate.type("myzset");
        System.out.println(type.name());
        System.out.println("===================================");
        //删除key
        redisTemplate.delete("myzset");
    }
}
